home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / doname.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  2KB  |  104 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: doname.c,v 1.4 1996/10/24 15:32:56 aros Exp $
  4.     $Log: doname.c,v $
  5.     Revision 1.4  1996/10/24 15:32:56  aros
  6.     Added missing include
  7.  
  8.     Revision 1.3  1996/09/21 14:14:23  digulla
  9.     Hand DOSBase to DoName()
  10.  
  11.     Revision 1.2  1996/09/13 17:50:06  digulla
  12.     Use IPTR
  13.  
  14.     Revision 1.1  1996/09/11 12:54:45  digulla
  15.     A couple of new DOS functions from M. Fleischer
  16.  
  17.     Desc:
  18.     Lang: english
  19. */
  20. #include <exec/memory.h>
  21. #include <clib/exec_protos.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/filesystem.h>
  24. #include <clib/dos_protos.h>
  25. #include <clib/utility_protos.h>
  26. #include <string.h>
  27. #include "dos_intern.h"
  28.  
  29. LONG DoName(struct IOFileSys *iofs, STRPTR name, struct DosLibrary * DOSBase)
  30. {
  31.     /* extern struct DosLibrary *DOSBase; */
  32.     STRPTR volname, pathname, s1;
  33.     BPTR cur;
  34.     struct DosList *dl;
  35.     struct Device *device;
  36.     struct Unit *unit;
  37.     struct FileHandle *fh;
  38.     struct Process *me=(struct Process *)FindTask(NULL);
  39.  
  40.     if(!Strnicmp(name,"PROGDIR:",8))
  41.     {
  42.     cur=me->pr_HomeDir;
  43.     volname=NULL;
  44.     pathname=name+8;
  45.     }else
  46.     {
  47.     /* Copy volume name */
  48.     cur=me->pr_CurrentDir;
  49.     s1=name;
  50.     pathname=name;
  51.     volname=NULL;
  52.     while(*s1)
  53.         if(*s1++==':')
  54.         {
  55.         volname=(STRPTR)AllocMem(s1-name,MEMF_ANY);
  56.         if(volname==NULL)
  57.             return me->pr_Result2=ERROR_NO_FREE_STORE;
  58.         CopyMem(name,volname,s1-name-1);
  59.         volname[s1-name-1]=0;
  60.         pathname=s1;
  61.         break;
  62.         }
  63.     }
  64.  
  65.     dl=LockDosList(LDF_ALL|LDF_READ);
  66.     if(volname!=NULL)
  67.     {
  68.     /* Find logical device */
  69.     dl=FindDosEntry(dl,volname,LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS);
  70.     if(dl==NULL)
  71.     {
  72.         UnLockDosList(LDF_ALL|LDF_READ);
  73.         FreeMem(volname,s1-name);
  74.         return me->pr_Result2=ERROR_DEVICE_NOT_MOUNTED;
  75.     }
  76.     device=dl->dol_Device;
  77.     unit  =dl->dol_Unit;
  78.     }else if(cur)
  79.     {
  80.     fh=(struct FileHandle *)BADDR(cur);
  81.     device=fh->fh_Device;
  82.     unit  =fh->fh_Unit;
  83.     }else
  84.     {
  85.     device=DOSBase->dl_NulHandler;
  86.     unit  =DOSBase->dl_NulLock;
  87.     }
  88.  
  89.     iofs->IOFS.io_Device =device;
  90.     iofs->IOFS.io_Unit     =unit;
  91.     iofs->io_Args[0]=(IPTR)pathname;
  92.  
  93.     /* Send the request. */
  94.     DoIO(&iofs->IOFS);
  95.  
  96.     if(dl!=NULL)
  97.     UnLockDosList(LDF_ALL|LDF_READ);
  98.  
  99.     if(volname!=NULL)
  100.     FreeMem(volname,s1-name);
  101.  
  102.     return me->pr_Result2=iofs->io_DosError;
  103. }
  104.